/**
 * 安装应用
 */
import { DependencyContainer, useTransaction, toSuccess, Router, HttpError } from '@sker/core'
import { useReqQuery, useUpload } from '@sker/runtime';
import { extname } from 'path';
import { z } from 'zod';
export default async (container: DependencyContainer) => {
    const router = new Router(container)
    const { scope, addon } = router;
    const input = z.object({
        name: z.string()
    })
    const body = input.parse(useReqQuery())
    const item = await useTransaction(async (m) => {
        const fileName = await useUpload(info => {
            const ext = extname(info.filename)
            if(ext !== '.png') throw new HttpError(`仅支持后缀名为.png的文件`)
            return `${body.name}.png`
        });
        return fileName;
    })
    return toSuccess(item)
}
